using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace Impact.Web.Admin.Controls
{
    public partial class ImageLinkButton : System.Web.UI.UserControl
    {
        private string commandArgument;
        private string targetUrl;
        private string cssClass;
        private string style;

        /// <summary>
        /// Event is fired when the user clicks the button
        /// </summary>
        public event CommandEventHandler Command;

        /// <summary>
        /// event handler is fired when the user clicks the button
        /// </summary>
        protected void OnCommand(object sender, CommandEventArgs e)
        {
            if (Command != null)
            {
                CommandEventArgs args = new CommandEventArgs(string.Empty, CommandArgument);
                Command(this, args);
            }
            if (!string.IsNullOrEmpty(TargetUrl))
            {
                Response.Redirect(TargetUrl);
            }
        }

        /// <summary>
        /// Gets or sets the javascript to insert in the onclick argument
        /// </summary>
        public string JavaScript
        {
            get { return linkButton.OnClientClick; }
            set { linkButton.OnClientClick = value; }
        }

        /// <summary>
        /// Gets or Sets the url of the image to be displayed on the button
        /// </summary>
        public string ImageUrl
        {
            get { return linkButton.Style[HtmlTextWriterStyle.BackgroundImage]; }
            set { linkButton.Style[HtmlTextWriterStyle.BackgroundImage] = value; }
        }

        /// <summary>
        /// Gets or Sets the Text to be displayed on the button
        /// </summary>
        public string Text
        {
            get { return linkButton.Text; }
            set { linkButton.Text = value; }
        }

        /// <summary>
        /// Gets or Sets an argument to send to the command event
        /// </summary>
        public string CommandArgument
        {
            get { return commandArgument; }
            set { commandArgument = value; }
        }

        /// <summary>
        /// Gets or Sets the Url that the button will redirect to when clicked.  
        /// The button will not redirect (just postback instead) if this value is null or empty
        /// </summary>
        public string TargetUrl
        {
            get { return targetUrl; }
            set { targetUrl = value; }
        }

        /// <summary>
        /// Gets or Sets the CSS class on the button
        /// </summary>
        public string CssClass
        {
            get { return cssClass; }
            set { cssClass = value; }
        }

        /// <summary>
        /// Gets or Sets the style on the button
        /// </summary>
        public string Style
        {
            get { return style; }
            set { style = value; }
        }

        /// <summary>
        /// Gets or Sets true if the button is to participate in validation of the page, false if not
        /// </summary>
        public bool CausesValidation
        {
            get { return linkButton.CausesValidation; }
            set { linkButton.CausesValidation = value; }
        }



    }
}